package com.sxfq.loansupermarket.backsystem.modular.system.controller;

import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.dysmsapi.model.v20170525.QuerySendDetailsRequest;
import com.aliyuncs.dysmsapi.model.v20170525.QuerySendDetailsResponse;
import com.aliyuncs.dysmsapi.model.v20170525.SendSmsRequest;
import com.aliyuncs.dysmsapi.model.v20170525.SendSmsResponse;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.profile.IClientProfile;
import com.sxfq.loansupermarket.backsystem.common.controller.BaseController;
import com.sxfq.loansupermarket.backsystem.common.node.MenuNode;
import com.sxfq.loansupermarket.backsystem.common.persistence.dao.UserMapper;
import com.sxfq.loansupermarket.backsystem.common.persistence.model.*;
import com.sxfq.loansupermarket.backsystem.core.log.LogManager;
import com.sxfq.loansupermarket.backsystem.core.log.factory.LogTaskFactory;
import com.sxfq.loansupermarket.backsystem.core.shiro.ShiroKit;
import com.sxfq.loansupermarket.backsystem.core.shiro.ShiroUser;
import com.sxfq.loansupermarket.backsystem.core.support.DateTimeKit;
import com.sxfq.loansupermarket.backsystem.core.support.HttpKit;
import com.sxfq.loansupermarket.backsystem.modular.arrival.entity.CustomerInfo;
import com.sxfq.loansupermarket.backsystem.modular.base.SqlMapper;
import com.sxfq.loansupermarket.backsystem.modular.basicData.service.IGetListService;
import com.sxfq.loansupermarket.backsystem.modular.system.dao.MenuDao;
import com.sxfq.loansupermarket.backsystem.modular.weixin.entity.ExtenAccountInfo;
import com.sxfq.loansupermarket.backsystem.modular.weixin.entity.WhUrlInfo;
import com.sxfq.loansupermarket.backsystem.modular.weixin.entity.WxTokenInfo;
import com.sxfq.loansupermarket.backsystem.modular.weixin.service.IWxService;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.ListOperations;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Random;

import com.sxfq.loansupermarket.backsystem.modular.system.service.ILoginService;

/**
 * 登录控制器
 *
 * @author fengshuonan
 * @Date 2017年1月10日 下午8:25:24
 */
@Controller
public class LoginController extends BaseController {
    @Autowired
    MenuDao menuDao;

    @Autowired
    IGetListService getListService;

    @Autowired
    private RedisTemplate redisTemplate;

    @Autowired
    ILoginService loginService;

    @Autowired
    UserMapper userMapper;

    @Autowired
    private SqlMapper sqlMapper;

    //产品名称:云通信短信API产品,开发者无需替换
    static final String product = "Dysmsapi";
    //产品域名,开发者无需替换
    static final String domain = "dysmsapi.aliyuncs.com";

    // TODO 此处需要替换成开发者自己的AK(在阿里云访问控制台寻找)
    static final String accessKeyId = "LTAIQMzfyJwlbjuU";

    static final String accessKeySecret = "8yCe7fywBbBkZbMS8dXkS2tZpELT6N";

    /**
     * 跳转到主页
     */
    @RequestMapping(value = "/", method = RequestMethod.GET)
    public String index(Model model) {
        List<Integer> roleList = ShiroKit.getUser().getRoleList();  //获取菜单列表
        if (roleList == null || roleList.size() == 0) {
            ShiroKit.getSubject().logout();
            String tips = "该用户没有角色，无法登陆";
            model.addAttribute("tips", tips);
            return "/login.html";
        }
        List<MenuNode> menus = menuDao.getMenusByRoleIds(roleList);
        List<MenuNode> titles = MenuNode.buildTitle(menus);
        Deptinfos dept = loginService.getDeptinfos();
        ShiroKit.setSessionAttr("titles", titles);
        WhUrlInfo whUrlInfo = loginService.getWhIpInfo();
        ExtenAccountInfo extenAccountInfo = loginService.getExten(ShiroKit.getUser().getAccount());
        model.addAttribute("whurl", whUrlInfo.getUrl());
        if (extenAccountInfo != null) {
            model.addAttribute("exten", extenAccountInfo.getExten());
        } else {
            model.addAttribute("exten", "2222");
        }
        model.addAttribute("abbreviation", dept.getAbbreviation());
        model.addAttribute("areaAbbreviation", dept.getAreaAbbreviation());
        model.addAttribute("abbreviation", dept.getAbbreviation());
        model.addAttribute("outpatientName", dept.getSimplename());
        model.addAttribute("proportional", dept.getProportional());
        model.addAttribute("sttleAccountsTime", dept.getSttleAccountsHour());
        model.addAttribute("deptid", dept.getId());
        model.addAttribute("userId",ShiroKit.getUser().getId());
        model.addAttribute("userName", ShiroKit.getUser().getAccount());
        model.addAttribute("avatar", redisTemplate.opsForList().index(ShiroKit.getUser().getAccount()+"Avatar",0)); //用户头像
        model.addAttribute("passWord", ShiroKit.getSessionAttr("password"));
        model.addAttribute("titles", ShiroKit.getSessionAttr("titles"));
        model.addAttribute("phonePrivileges", redisTemplate.opsForList().index(ShiroKit.getUser().getAccount()+"PhonePrivileges",0));  //是否能查看列表电话
        model.addAttribute("phonePrivilegesexp", redisTemplate.opsForList().index(ShiroKit.getUser().getAccount()+"PhonePrivilegesexp",0));  //是否能导出列表电话
        String tips = "登录成功";
        model.addAttribute("tips", tips);
        return "/index.html";
    }

    /**
     * 跳转到主页
     */
    @RequestMapping(value = "/index", method = RequestMethod.GET)
    public String to_index(Model model) {
        if (ShiroKit.getSessionAttr("username") == null || "null".equals(ShiroKit.getSessionAttr("username"))) {
            ShiroKit.getSubject().logout();
            model.addAttribute("tips", "");
            return "/login.html";
        }
        String tips = "";
        Deptinfos dept = loginService.getDept();
        Userinfos user = loginService.getUser();
        Test test = loginService.getTest();
        WxTokenInfo wxTokenInfo=loginService.getWxToken(dept.getAreaAbbreviation());
        if (user != null) {
        } else {
            Userinfos user1 = loginService.getUserinfos();
            if (user1 != null) {
                if (user1.getName().indexOf("总公司") != -1) {
                    user = user1;
                }
            } else {
                ShiroKit.getSubject().logout();
                tips = "该用户没有权限登陆该诊所";
                model.addAttribute("tips", tips);
                return "/login.html";
            }
        }
        List<Integer> roleList = ShiroKit.getUser().getRoleList();  //获取菜单列表
        if (roleList == null || roleList.size() == 0) {
            ShiroKit.getSubject().logout();
            tips = "该用户没有角色，无法登陆";
            model.addAttribute("tips", tips);
            return "/login.html";
        }
        WhUrlInfo whUrlInfo = loginService.getWhIpInfo();
        ExtenAccountInfo extenAccountInfo = loginService.getExten(user.getAccount());
        model.addAttribute("whurl", whUrlInfo.getUrl());
        if (extenAccountInfo != null) {
            model.addAttribute("exten", extenAccountInfo.getExten());
        } else {
            model.addAttribute("exten", "2222");

        }
        redisTemplate.opsForList().leftPush(ShiroKit.getUser().getAccount()+"areaList",getListService.areaList());
        redisTemplate.opsForList().leftPush(ShiroKit.getUser().getAccount()+"LowestPriceBill",dept.getLowestPriceBill());
        redisTemplate.opsForList().leftPush(ShiroKit.getUser().getAccount()+"DeptName",user.getName());
        redisTemplate.opsForList().leftPush(ShiroKit.getUser().getAccount()+"Abbreviation",dept.getAbbreviation());
        redisTemplate.opsForList().leftPush(ShiroKit.getUser().getAccount()+"customer_info",dept.getAbbreviation()+"customer_info");
        redisTemplate.opsForList().leftPush(ShiroKit.getUser().getAccount()+"vip_level_info",dept.getAreaAbbreviation()+"vip_level_info");
        redisTemplate.opsForList().leftPush(ShiroKit.getUser().getAccount()+"pay_service_vip",dept.getAreaAbbreviation()+"pay_service_vip");
        redisTemplate.opsForList().leftPush(ShiroKit.getUser().getAccount()+"pay_service_members",dept.getAreaAbbreviation()+"pay_service_members");
        redisTemplate.opsForList().leftPush(ShiroKit.getUser().getAccount()+"pay_service_grade_info",dept.getAreaAbbreviation()+"pay_service_grade_info");
        redisTemplate.opsForList().leftPush(ShiroKit.getUser().getAccount()+"pay_service_info",dept.getAreaAbbreviation()+"pay_service_info");
        redisTemplate.opsForList().leftPush(ShiroKit.getUser().getAccount()+"deal_info",dept.getAbbreviation()+"deal_info");
        redisTemplate.opsForList().leftPush(ShiroKit.getUser().getAccount()+"recharge_info",dept.getAbbreviation()+"recharge_info");
        redisTemplate.opsForList().leftPush(ShiroKit.getUser().getAccount()+"triage_performance",dept.getAbbreviation()+"triage_performance");
        redisTemplate.opsForList().leftPush(ShiroKit.getUser().getAccount()+"medicalrecord_info",dept.getAbbreviation()+"medicalrecord_info");
        redisTemplate.opsForList().leftPush(ShiroKit.getUser().getAccount()+"MemberSwitch",dept.getMemberSwitch());
        redisTemplate.opsForList().leftPush(ShiroKit.getUser().getAccount()+"Auditswitch",dept.getAuditswitch());
        redisTemplate.opsForList().leftPush(ShiroKit.getUser().getAccount()+"AuditOfDept",dept.getAuditofdept());
        redisTemplate.opsForList().leftPush("APPID",wxTokenInfo.getAppId());
        redisTemplate.opsForList().leftPush("AppSecret",wxTokenInfo.getAppSecret());
        redisTemplate.opsForList().leftPush(ShiroKit.getUser().getAccount()+"SttleAccountsTime",dept.getSttleAccountsHour());
        redisTemplate.opsForList().leftPush(ShiroKit.getUser().getAccount()+"Province",dept.getProvince());
        redisTemplate.opsForList().leftPush(ShiroKit.getUser().getAccount()+"AreaAbbreviation",dept.getAreaAbbreviation());
        redisTemplate.opsForList().leftPush(ShiroKit.getUser().getAccount()+"Fullname",dept.getFullname());
        redisTemplate.opsForList().leftPush(ShiroKit.getUser().getAccount()+"Phone",dept.getPhone());
        redisTemplate.opsForList().leftPush(ShiroKit.getUser().getAccount()+"Address",dept.getAddress());
        redisTemplate.opsForList().leftPush(ShiroKit.getUser().getAccount()+"Cities",dept.getCities());
        redisTemplate.opsForList().leftPush(ShiroKit.getUser().getAccount()+"Dealyes",user.getDealyes());
        redisTemplate.opsForList().leftPush(ShiroKit.getUser().getAccount()+"Proportional",dept.getProportional());
        redisTemplate.opsForList().leftPush(ShiroKit.getUser().getAccount()+"Version",user.getVersion());
        redisTemplate.opsForList().leftPush(ShiroKit.getUser().getAccount()+"IsRefundAdmin",user.getIsRefundAdmin());
        redisTemplate.opsForList().leftPush(ShiroKit.getUser().getAccount()+"RegisterIsRing",user.getRegisterIsRing());
        redisTemplate.opsForList().leftPush(ShiroKit.getUser().getAccount()+"DoctorRoleId",test.getId1());
        redisTemplate.opsForList().leftPush(ShiroKit.getUser().getAccount()+"DentistRoleId",test.getId2());
        redisTemplate.opsForList().leftPush(ShiroKit.getUser().getAccount()+"PublicDoctorRoleId",test.getId3());
        redisTemplate.opsForList().leftPush(ShiroKit.getUser().getAccount()+"DeptId",dept.getId());
        redisTemplate.opsForList().leftPush(ShiroKit.getUser().getAccount()+"ChannelAuditLevel",user.getChannelAuditLevel());
        redisTemplate.opsForList().leftPush(ShiroKit.getUser().getAccount()+"LevelTwoAudit",dept.getLevelTwoAudit());
        redisTemplate.opsForList().leftPush(ShiroKit.getUser().getAccount()+"AuditNode",user.getAuditNode());
        redisTemplate.opsForList().leftPush(ShiroKit.getUser().getAccount()+"RoleName",user.getRoleName());
        redisTemplate.opsForList().leftPush(ShiroKit.getUser().getAccount()+"Avatar",user.getAvatar());
        redisTemplate.opsForList().leftPush(ShiroKit.getUser().getAccount()+"PhonePrivileges",user.getPhonePrivileges()); //是否能查看列表电话
        redisTemplate.opsForList().leftPush(ShiroKit.getUser().getAccount()+"PhonePrivilegesexp",user.getPhonePrivilegesexp()); //是否能导出列表电话
        redisTemplate.opsForList().leftPush(ShiroKit.getUser().getAccount()+"DoctorInfoList",null);
        redisTemplate.opsForList().leftPush(ShiroKit.getUser().getAccount()+"MedicalUpPermission",null);
        redisTemplate.opsForList().leftPush(ShiroKit.getUser().getAccount()+"jysList",null);
        redisTemplate.opsForList().leftPush(ShiroKit.getUser().getAccount()+"nursesList",null);
        redisTemplate.opsForList().leftPush(ShiroKit.getUser().getAccount()+"nursesLists",null);

        ShiroKit.getUser().setId(user.getId());
        model.addAttribute("dentistRoleId", test.getId2());
        model.addAttribute("doctorRoleId", test.getId1());
        model.addAttribute("publicDoctorRoleId", test.getId3());
        model.addAttribute("proportional", dept.getProportional());
        model.addAttribute("sttleAccountsTime", dept.getSttleAccountsHour());
        model.addAttribute("abbreviation", dept.getAbbreviation());
        model.addAttribute("areaAbbreviation", dept.getAreaAbbreviation());
        model.addAttribute("abbreviation", dept.getAbbreviation());
        model.addAttribute("outpatientName", dept.getSimplename());
        model.addAttribute("deptid", dept.getId());
        model.addAttribute("userId", user.getId());
        model.addAttribute("userName", user.getAccount());
        model.addAttribute("avatar", user.getAvatar()); //用户头像
        model.addAttribute("passWord", ShiroKit.getSessionAttr("password"));
        model.addAttribute("titles", ShiroKit.getSessionAttr("titles"));
        model.addAttribute("phonePrivileges", user.getPhonePrivileges());  //是否能查看列表电话
        model.addAttribute("phonePrivilegesexp", user.getPhonePrivilegesexp());  //是否能导出列表电话
        tips = "登录成功";
        model.addAttribute("tips", tips);
        ShiroKit.setSessionAttr("tips", tips);
        return "/index.html";
    }

    //得到子集
    @RequestMapping(value = "/getChildrenValue", method = RequestMethod.POST)
    @ResponseBody
    public List<MenuNode> getChildrenValue(String code, HttpServletResponse response) {
        String accounCodeChildlist = ShiroKit.getUser().getAccount() + code + "childrenValueList";
        if (ShiroKit.getSessionAttr(accounCodeChildlist) == null) {
            String sql = "select b.name as name,b.url as url from role a left join relation c on a.id=c.roleid " +
                    " left join menu b on c.menuid=b.id left join user d on find_in_set(a.id,d.roleid) > 0 " +
                    " where d.account='" + ShiroKit.getUser().getAccount() + "' " +
                    " and pcode='" + code + "' and b.ismenu=1 group by b.id order by b.num";
            ShiroKit.setSessionAttr(accounCodeChildlist, sqlMapper.selectList(sql));
            return ShiroKit.getSessionAttr(accounCodeChildlist);
        } else {
            return ShiroKit.getSessionAttr(accounCodeChildlist);
        }
    }

    @Autowired
    private IWxService wxService;

    /**
     * 跳转到登录页面
     */
    @RequestMapping(value = "/login", method = RequestMethod.GET)
    public String login(Model model, HttpServletResponse response) {
        model.addAttribute("tips", "");
//        wxService.questionnaire(); //问卷调查推送
        return "/login.html";
    }

    /**
     * 点击登录执行的动作
     */
    @RequestMapping(value = "/login", method = RequestMethod.POST)
    public String loginVali(HttpServletResponse response) throws ClientException, InterruptedException {
        response.setHeader("Access-Control-Allow-Origin", "*");
        ShiroKit.setSessionAttr("tips", "");
        String username = super.getPara("username").trim();
        String password = super.getPara("password").trim();
        String outpatientName = super.getPara("outpatientName").trim();
        Subject currentUser = ShiroKit.getSubject();
        UsernamePasswordToken token = new UsernamePasswordToken(username, password.toCharArray());
        List<Map<String, Object>> outpatientManagementList = getListService.outpatientManagementList();
        ShiroKit.setSessionAttr("outpatientManagementList", outpatientManagementList);
        token.setRememberMe(true);
        currentUser.login(token);
        ShiroUser shiroUser = ShiroKit.getUser();
        super.getSession().setAttribute("shiroUser", shiroUser);
        super.getSession().setAttribute("username", shiroUser.getAccount());
        super.getSession().setAttribute("outpatientName", outpatientName);
        LogManager.me().executeLog(LogTaskFactory.loginLog(shiroUser.getId(), HttpKit.getIp()));
        ShiroKit.getSession().setAttribute("sessionFlag", true);
        ShiroKit.getUser().setOutpatientName(outpatientName);
        ShiroKit.setSessionAttr("username", username);
        ShiroKit.setSessionAttr("password", password);
//        activity();
        return REDIRECT + "/";
    }

    //参与12月种植返现活动
    public void activity() throws ClientException, InterruptedException {
        String time = DateTimeKit.now();
        String sql11 = "select * from reservemoney_activity limit 1";
        CustomerInfo a = sqlMapper.selectOne(sql11, CustomerInfo.class);
        if ("01".equals(time.substring(8, 10)) && "2020".equals(time.substring(0, 4)) && !(time.substring(5, 7)).equals(a.getStatuss())) {  //20年每月的1号
            String sql2r = " INSERT INTO reserveMoney_deal (`status`, `reservations_id`, `customer_id`," +
                    "  `recharge_people`,`checkout_method_id`, `checkout_method`, " +
                    "  `actual_account_balance`, `recharge_time`, `operation_time`, " +
                    "  `remarks`, `is_record`,tc_name,add_store,mode,deal_id)    " +
                    " select status,reservations_id,customer_id, " +
                    " recharge_people,checkout_method_id,checkout_method,ROUND(actual_account_balance/12,1),recharge_time,operation_time, " +
                    " remarks,is_record,tc_name,add_store,mode,deal_id from reservemoney_activity ";
            sqlMapper.insert(sql2r);
            String sql = "select * from reservemoney_activity ";
            List<CustomerInfo> dept = sqlMapper.selectList(sql, CustomerInfo.class);
            for (CustomerInfo d : dept) {
                String tableNamer = d.getAbbreviation() + "recharge_info";
                Random rand = new Random();
                int randomNumber = rand.nextInt(999999);
                String id = randomNumber + d.getRechargeTime() + d.getId();
                String sql2 = " INSERT INTO `" + tableNamer + "` (`id`, `status`, `customer_id`, `reservations_id`, " +
                        "  `recharge_people`,`checkout_method_id`, `checkout_method`, " +
                        "  `actual_account_balance`, `recharge_time`, `operation_time`, " +
                        "  `remarks`, `is_record`,tc_name,isEarnes,hospital_performance,section_performance)   " +
                        " select '" + id + "',1,customer_id,reservations_id,recharge_people,checkout_method_id,checkout_method," +
                        "  ROUND(actual_account_balance/12,1),recharge_time,operation_time, " +
                        "  remarks,'是',tc_name,2,ROUND(actual_account_balance/12,1),0" +
                        " from reservemoney_activity where abbreviation='" + d.getAbbreviation() + "' and recharge_time='" + d.getRechargeTime() + "'";
                sqlMapper.insert(sql2);
                String sql1 = "select * from " + d.getAbbreviation() + "customer_info" + " where reservations_id='" + d.getReservationsId() + "' limit 0,1";
                CustomerInfo cu = sqlMapper.selectOne(sql1, CustomerInfo.class);
                String signName = "钛植口腔" + d.getAddStore();
                String phoneNumbers = cu.getCustomerPhone();
                //String TemplateParam = "";
                //组装请求对象-具体描述见控制台-文档部分内容
                SendSmsRequest request = new SendSmsRequest();
                //必填:待发送手机号
                request.setPhoneNumbers(phoneNumbers);
                //必填:短信签名-可在短信控制台中找到
                request.setSignName(signName);
                //必填:短信模板-可在短信控制台中找到
                request.setTemplateCode("SMS_180353075");
                //可选:模板中的变量替换JSON串,如模板内容为"亲爱的${name},您的验证码为${code}"时,此处的值为
                //选填-上行短信扩展码(无特殊需求用户请忽略此字段)
                //request.setSmsUpExtendCode("90997");
                //可选:outId为提供给业务方扩展字段,最终在短信回执消息中将此值带回给调用者
                request.setOutId("123");
                //发短信
                SendSmsResponse response = sendSms(request);
                System.out.println("短信接口返回的数据----------------");
                System.out.println("Code=" + response.getCode());
                System.out.println("Message=" + response.getMessage());
                System.out.println("RequestId=" + response.getRequestId());
                System.out.println("BizId=" + response.getBizId());
                Thread.sleep(300L);
                //查明细
                if (response.getCode() != null && response.getCode().equals("OK")) {
                    QuerySendDetailsResponse querySendDetailsResponse = querySendDetails(response.getBizId());
                    System.out.println("短信明细查询接口返回数据----------------");
                    System.out.println("Code=" + querySendDetailsResponse.getCode());
                    System.out.println("Message=" + querySendDetailsResponse.getMessage());
                    int i = 0;
                    for (QuerySendDetailsResponse.SmsSendDetailDTO smsSendDetailDTO : querySendDetailsResponse.getSmsSendDetailDTOs()) {
                        System.out.println("SmsSendDetailDTO[" + i + "]:");
                        System.out.println("Content=" + smsSendDetailDTO.getContent());
                        System.out.println("ErrCode=" + smsSendDetailDTO.getErrCode());
                        System.out.println("OutId=" + smsSendDetailDTO.getOutId());
                        System.out.println("PhoneNum=" + smsSendDetailDTO.getPhoneNum());
                        System.out.println("ReceiveDate=" + smsSendDetailDTO.getReceiveDate());
                        System.out.println("SendDate=" + smsSendDetailDTO.getSendDate());
                        System.out.println("SendStatus=" + smsSendDetailDTO.getSendStatus());
                        System.out.println("Template=" + smsSendDetailDTO.getTemplateCode());
                    }
                    System.out.println("TotalCount=" + querySendDetailsResponse.getTotalCount());
                    System.out.println("RequestId=" + querySendDetailsResponse.getRequestId());
                    String insertsql = "INSERT INTO `msg_send_info` ( `sender`, `customer_name`, `customer_phone`, `message_content`, `outpatient_name`, `is_success`) VALUES" +
                            "('" + ShiroKit.getUser().getAccount() + "', '" + cu.getCustomerName() + "', '" + cu.getCustomerPhone()
                            + "', '您好,参与活动的费用已返还，钛植口腔，您身边的口腔健康专家。','" + ShiroKit.getUser().getOutpatientName() + "',1);";
                    sqlMapper.insert(insertsql);
                } else {
                    String insertsql = "INSERT INTO `msg_send_info` ( `sender`, `customer_name`, `customer_phone`, `message_content`,`outpatient_name`, `is_success`) VALUES" +
                            "('" + ShiroKit.getUser().getAccount() + "', '" + cu.getCustomerName() + "', '" + cu.getCustomerPhone()
                            + "', '您好,参与活动的费用已返还，钛植口腔，您身边的口腔健康专家。','" + ShiroKit.getUser().getOutpatientName() + "',2);";
                    sqlMapper.insert(insertsql);
                }
            }
            String sqlup = "update reservemoney_activity set statuss='" + time.substring(5, 7) + "' ";
            sqlMapper.update(sqlup);  //当月存入数据
        }
    }

    public static SendSmsResponse sendSms(SendSmsRequest request) throws ClientException {
        //可自助调整超时时间
        System.setProperty("sun.net.client.defaultConnectTimeout", "10000");
        System.setProperty("sun.net.client.defaultReadTimeout", "10000");
        //初始化acsClient,暂不支持region化
        IClientProfile profile = DefaultProfile.getProfile("cn-hangzhou", accessKeyId, accessKeySecret);
        DefaultProfile.addEndpoint("cn-hangzhou", "cn-hangzhou", product, domain);
        IAcsClient acsClient = new DefaultAcsClient(profile);
        //hint 此处可能会抛出异常，注意catch
        SendSmsResponse sendSmsResponse = acsClient.getAcsResponse(request);
        return sendSmsResponse;
    }

    public static QuerySendDetailsResponse querySendDetails(String bizId) throws ClientException {
        //可自助调整超时时间
        System.setProperty("sun.net.client.defaultConnectTimeout", "10000");
        System.setProperty("sun.net.client.defaultReadTimeout", "10000");
        //初始化acsClient,暂不支持region化
        IClientProfile profile = DefaultProfile.getProfile("cn-hangzhou", accessKeyId, accessKeySecret);
        DefaultProfile.addEndpoint("cn-hangzhou", "cn-hangzhou", product, domain);
        IAcsClient acsClient = new DefaultAcsClient(profile);
        //组装请求对象
        QuerySendDetailsRequest request = new QuerySendDetailsRequest();
        //必填-号码
        request.setPhoneNumber("18602744660");
        //可选-流水号
        request.setBizId(bizId);
        //必填-发送日期 支持30天内记录查询，格式yyyyMMdd
        SimpleDateFormat ft = new SimpleDateFormat("yyyyMMdd");
        request.setSendDate(ft.format(new Date()));
        //必填-页大小
        request.setPageSize(10L);
        //必填-当前页码从1开始计数
        request.setCurrentPage(1L);
        //hint 此处可能会抛出异常，注意catch
        QuerySendDetailsResponse querySendDetailsResponse = acsClient.getAcsResponse(request);
        return querySendDetailsResponse;
    }

    /**
     * 退出登录
     */
    @RequestMapping(value = "/logout", method = RequestMethod.GET)
    public String logOut() {
        LogManager.me().executeLog(LogTaskFactory.exitLog(ShiroKit.getUser().getId(), HttpKit.getIp()));
        ShiroKit.getSubject().logout();
        return REDIRECT + "/login";
    }
}